package com.example.xianji.adapter;

import java.util.ArrayList;

import com.example.xianji.activity.Main_Skill_DetailsActivity;
import com.example.xianji.R;
import com.example.xianji.bean.Skill;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class SkillAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<Skill> list;

    public SkillAdapter(Context context, ArrayList<Skill> list) {
        super();
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder mHolder;
        if (convertView == null) {
            mHolder = new Holder();
            convertView = View.inflate(context, R.layout.skill_lietview_layout, null);
            mHolder.skill_title = (TextView) convertView.findViewById(R.id.junming_ronghe_title);
            mHolder.skill_parent_name = (TextView) convertView.findViewById(R.id.junming_ronghe_parent_name);
            convertView.setTag(mHolder);

        }
        mHolder = (Holder) convertView.getTag();
        mHolder.skill_title.setText(list.get(position).getTitle());
        mHolder.skill_parent_name.setText("分类专属  :  " + list.get(position).getName());
        final int a = position;
        convertView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, Main_Skill_DetailsActivity.class);
                intent.putExtra("skill_id", list.get(a).getId());
                context.startActivity(intent);
            }
        });
        return convertView;
    }

    class Holder {
        TextView skill_title;
        TextView skill_parent_name;
    }
}
